package landun.dao.impl;

import landun.dao.BaseDao;
import landun.dao.BizClaimVoucherDetailDao;
import landun.pojo.BizClaimVoucherDetail;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;

/**
 * 报销明细
 */
@Repository("bizClaimVoucherDetailDao")
public class BizClaimVoucherDetailDaoImpl extends BaseDao<BizClaimVoucherDetail> implements BizClaimVoucherDetailDao {

    @Autowired
    public BizClaimVoucherDetailDaoImpl(SessionFactory sessionFactory) {
        super.setSessionFactory(sessionFactory);
    }

    @Override
    public BizClaimVoucherDetail findDetailById(final Integer id) {
        return getHibernateTemplate().execute(new HibernateCallback<BizClaimVoucherDetail>() {
            @Override
            public BizClaimVoucherDetail doInHibernate(Session session) throws HibernateException, SQLException {
                return (BizClaimVoucherDetail)session.
                        createQuery("from BizClaimVoucherDetail where mainId=?").
                        setParameter(0,id).uniqueResult();
            }
        });
    }

    @Override
    public void save(BizClaimVoucherDetail bizClaimVoucherDetail) {
        getHibernateTemplate().saveOrUpdate(bizClaimVoucherDetail);
    }

    @Override
    public void delete(BizClaimVoucherDetail bizClaimVoucherDetail) {

    }
}
